package router

import (
	"github.com/gin-gonic/gin"
	v1 "syuee.com/iShot/controller/api/private/v1"
	"syuee.com/iShot/middleware"
)

func ApiRoutersInit(r *gin.Engine) *gin.Engine{
	//解决浏览器跨域问题
	r.Use(middleware.CORSMiddleware())
	//r.Use(middleware.Cors())
	r.POST("/api/private/v1/login/", v1.UserController{}.Login)
	r.POST("/api/private/v1/register/", v1.UserController{}.Register)

	v1GroupUserApi := r.Group("/api/private/v1", middleware.AuthMiddleware())
	{
		v1GroupUserApi.GET("/users/", v1.UserController{}.GetAllManagers)
		v1GroupUserApi.POST("/users/", v1.UserController{}.CreateManager)
		v1GroupUserApi.PUT("/users/:uid/state/:type", v1.UserController{}.UpdateManagerState)
		v1GroupUserApi.GET("/users/:id", v1.UserController{}.GetManager)
		v1GroupUserApi.PUT("/users/:uid", v1.UserController{}.UpdateManager)
		v1GroupUserApi.DELETE("/users/:id", v1.UserController{}.DeleteManager)
		v1GroupUserApi.GET("/users/:id/role", v1.UserController{}.SetRole)
	}
	return r
}
